﻿using Colorful.Cache;
using Colorful.Database;
using Microsoft.Extensions.Configuration;
using NLog;
using NLog.Config;
using PeterKottas.DotNetCore.WindowsService.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ColorCMS.Service
{
    public class Service : IMicroService
    {
        private ILogger logger;
        public void Start()
        {
            logger = LogManager.GetLogger("Service");
            logger.Info("log info");
            logger.Debug("log debug");

            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();
            var appSetting = configuration.GetSection("AppSetting");
            var databaseSetting = configuration.GetSection("Database");
            //Mongodb
            var mongodbSetting = databaseSetting.GetSection("Mongodb");
            DbSetting.Database = mongodbSetting.GetValue<string>("DatabaseName");
            DbSetting.ConnectionString = mongodbSetting.GetValue<string>("ConnectionString");
            //Redis
            CacheSetting.Prefix = appSetting.GetValue<string>("ProjectId");
            CacheSetting.ConnectionString = databaseSetting.GetValue<string>("Redis");


        }

        public void Stop()
        {
        }
    }
}
